var path = require('path');
var http = require('http');
var express = require('express');
var proxy = require('express-http-proxy');
//使用proxyTable
var proxyMiddleware = require('http-proxy-middleware');

var app = express();

// 测试服务器
// var serverIp = 'http://192.168.1.143:20100';
// 正式服务器
var serverIp = 'http://58.241.186.230:8383/drugTraceability';

var proxyTable = {
  '/V1.0.0/drugInfo': {
    target: serverIp,
    changeOrigin: true,
  },
  '/V1.0.0/account': {
    target: serverIp,
    changeOrigin: true,
  },
  '/V1.0.0/storageWarehouse': {
    target: serverIp,
    changeOrigin: true,
  },
  '/V1.0.0/leaveWarehouse': {
    target: serverIp,
    changeOrigin: true,
  },
  '/V1.0.0/distributor': {
    target: serverIp,
    changeOrigin: true,
  },
  '/V1.0.0/leaveWarehouseDetail': {
    target: serverIp,
    changeOrigin: true,
  },
  '/V1.0.0/supervisionWrapper': {
    target: serverIp,
    changeOrigin: true,
  }
}

// 将 proxyTable 中的请求 配置挂载到启动的express服务上
Object.keys(proxyTable).forEach(function (context) {
  var options = proxyTable[context]
  if (typeof options === 'string') {
    options = {
      target: options
    }
  }
  app.use(proxyMiddleware(context, options))
})


app.use(express.static(path.join(__dirname, '/dist/')));


var server = http.createServer(app);


app.listen(8085, function () {
  console.log('success')
});
